import pygame;

class CutsceneView(object):
    '''
    Class which will be called by the conductor to 
    display cutscenes for the story.
    
    Cutscenes are a series sceneDescription objects
    '''


    def __init__(self, imageFolder, background, window):
        self._imageFolder=imageFolder+'\\'
        #self._images=self.loadImages()
        pygame.init()
        self._masterWindow = window;
        self._window = window.window();
        self._screenHeight = window.height();
        self._screenWidth = window.width();
        self._background = self.scaleFullscreen(self.loadImage(background))
        
    
    def loadImage(self,name):
        return(pygame.image.load(self._imageFolder+name))
    
    def imagePosition(self,image,pos,offset):
        ystart = self._screenHeight-image.get_height()-offset[1]
        if pos == "left":
            return(0-offset[0],ystart)
        if pos == "right":
            xstart = self._screenWidth-image.get_width()-offset[0]
            return (xstart,ystart)
        if pos == "full":
            return(0,0)
        
    def scaleFullscreen(self,image): 
        return pygame.transform.scale(image, (self._screenWidth,self._screenHeight))
    
    def update(self, subject):
        self._window.fill((255,255,255))
        self._window.blit(self._background,(0,0))
        if subject.image:
            image = self.loadImage(subject.image)
            if subject.position == "full":
                image = self.scaleFullscreen(image);
            pos = self.imagePosition(image, subject.position,(0,self._masterWindow.textHeight))
            self._window.blit(image,pos);
        if not subject.isLongText:
            self._masterWindow.displayText(subject.text)
        else:
            self._masterWindow.displayLongText(subject.text)
        pygame.display.update()